<?php
require_once( '../need.inc.php' );
Login::NeedLogin();

$id = $table = $modify_id = $modify_table = null;
extract( $_GET, EXTR_IF_EXISTS );

if ( !$id || !$table )
{
	if ( !$modify_id && !$modify_table )
	{
		die( Template::Render('error_tips', array('error','参数不完整')));
	}
	else
	{
		$id = $modify_id;
		$table = $modify_table;
	}
}

$select_map = array();
$nake_fields = DB::GetField( $table, $select_map );
$fields = Utility::AssColumn( $nake_fields, 'cate', 'name' );

/* 更新ACTION */
if ( $modify_table && $modify_id )
{

	$field_names = Utility::GetColumn( $nake_fields, 'name' );
	$update_array = array();
	foreach( $_GET AS $key=>$value )
	{
		if( in_array( $key, $field_names ) )
		{
			$value = is_array($value) ? implode(',',$value) : $value; //for Type:set
			$update_array[ $key ] = $value;
		}
	}

	DB::saveTableRow ( $table, $update_array );
}

/* get record by id */
$record = Table::Fetch( $table, $id );

//We only NEED know four type, INT,VARCHAR,TEXT,ENUM;
$map = array(
	'id' => 'ID',
	'name' => '名称',
	'time_create' => '创建时间',
	'access' => '访问权限',
	'intro' => '描述',
	'user_id' => '用户ID',
	'video_id' => '视频ID',
	'count_comment' => '评论数',
	'count_pic' => '图片数',
	'count_topic' => '主题数',
	'count_reply' => '回复数',
	'count_click' => '点击数',
	'count_user' => '用户数',
	'tag' => '标签',
	'text' => '正文',
	'column_id' => '栏目',
	'title' => '标题',
	'content' => '正文',
	'secret' => '访问密钥',
	'draft' => '草稿',
);

/* get field */
$ft = array(
	'id' => '主键',
	'time' => '时间属性',
	'fkey' => '外键属性',
	'select' => '选择属性',
	'text' => '文本属性',
	'count' => '计数属性',
	'other' => '其他属性',
);

/* display */
Template::Display( 'edit_unified', array(
	'id' => $id,
	'table' => $table,
	'fields' => $fields,
	'map' => $map,
	'record' => $record,
	'ft' => $ft,
));
?>
